﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using ELGGAPI.Models;
using ELGGAPI.Data;


namespace ELGGAPI.Controllers
{
    public class AlbumController : ApiController
    {
        //
        // GET: /Album/

        public Response<AlbumModels> GetAlbums(string access_token)
        {
            var response = new Response<AlbumModels>();
            try
            {
                var user = AutheticationToken.ValidateToken(access_token);
                if (user == null)
                {
                    response.Data = null;
                    response.Message = "Token is invalid";
                    return response;
                }
                else
                {
                    response.Data = AlbumDomainModels.GetAlbumList(user.id);
                }
                return (response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return response;
            }
        }

        public Response<ImageModels> GetImages(string access_token, string albumid)
        {
            var response = new Response<ImageModels>();
            try
            {
                var user = AutheticationToken.ValidateToken(access_token);
                if (user == null)
                {
                    response.Data = null;
                    response.Message = "Token is invalid";
                    return response;
                }
                else
                {
                    int intalbumid = int.Parse("0" + albumid);
                    response.Data = AlbumDomainModels.GetImageList(intalbumid);
                }
                return (response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return response;
            }
        }
    }
}
